package com.compass.doctor.ui.chat.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.compass.doctor.R
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.databinding.CustomChatButtonBinding
import com.compass.framework.ext.gone
import com.compass.framework.ext.visible
import com.compass.framework.manager.UserInfoManager
import com.netease.yunxin.kit.chatkit.ui.view.input.ActionConstants


/**
 * Description： 自定义输入框上方按钮
 * Date:2023/12/1 9:10
 */
class CustomChatBottomView : LinearLayout, View.OnClickListener {
    private lateinit var customChatButtonBinding: CustomChatButtonBinding
    private var context: Context
    private var onChatBottomClick: OnCustomButtonClick? = null


    constructor(context: Context) : super(context) {
        this.context = context
        initView(context)
    }

    constructor(
        context: Context,
        attrs: AttributeSet?,
        onChatBottomClick: OnCustomButtonClick?
    ) : super(context, attrs) {
        this.context = context
        this.onChatBottomClick = onChatBottomClick
        initView(context)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        this.context = context
        initView(context)
    }

    //初始化UI，可根据业务需求设置默认值。
    private fun initView(context: Context) {
        customChatButtonBinding =
            CustomChatButtonBinding.inflate(LayoutInflater.from(context), this, true)
        customChatButtonBinding.rapidPrescribing.setOnClickListener(this)
        customChatButtonBinding.usefulExpressions.setOnClickListener(this)
        customChatButtonBinding.numberOfGifts.setOnClickListener(this)


    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.rapid_prescribing -> {
                onChatBottomClick?.onButtonCallBack(1, ActionConstants.RAPID_PRESCRIBING)
            }

            R.id.useful_expressions -> {
                onChatBottomClick?.onButtonCallBack(2, ActionConstants.USEFUL_EXPRESSIONS)
            }

            R.id.number_of_gifts -> {
                onChatBottomClick?.onButtonCallBack(3, ActionConstants.PRESENTED_NUMBER)
            }
        }
    }

    /**
     * 显示快速开药
     * @param isInquiry 是否有问诊单
     * @param ifReturnVisit 是否是复诊
     */
    fun showPrescribe(isInquiry: Boolean, ifReturnVisit: String?) {

        //是否验证复诊
//        val isFollowUp = UserInfoManager.getUserInfo()?.appHospitalConfigRespVO?.isFollowUp
//        //验证复诊 且是复诊 且是医生
//        if (isFollowUp == "1" && ifReturnVisit == "1" && UserInfoManager.getUserType() == "1") {
//            if (isInquiry) customChatButtonBinding.rapidPrescribing.visible() else customChatButtonBinding.rapidPrescribing.gone()
//        } else if (isFollowUp != "1" && UserInfoManager.getUserType() == "1") {
//            //不验证复诊 切是医生
//            if (isInquiry) customChatButtonBinding.rapidPrescribing.visible() else customChatButtonBinding.rapidPrescribing.gone()
//        } else {
//            customChatButtonBinding.rapidPrescribing.gone()
//        }


        //且是医生
        if (UserInfoManager.getUserType() == "1"&&isInquiry) {
            customChatButtonBinding.rapidPrescribing.visible()
        }else {
            customChatButtonBinding.rapidPrescribing.gone()
        }

    }


    /**
     * 显示赠送按钮
     */
    fun showGift() {
        val appHospitalConfig = UserInfoManager.getUserInfo()?.appHospitalConfigRespVO

        appHospitalConfig?.let {
            if (it.isAllowGive == "1") customChatButtonBinding.numberOfGifts.visible() else customChatButtonBinding.numberOfGifts.gone()
        } ?: kotlin.run {
            customChatButtonBinding.numberOfGifts.gone()
        }


    }


}